<template>
  <!-- 一条文章单元格 -->
  <div>
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ artObj.title }}</span>
          <!-- 图片显示 单图-->
          <lazy-component>
          <img
            class="thumb"
            v-if="artObj.cover.type === 1"
            v-lazy="artObj.cover.images[0]"
            alt=""
          />
          </lazy-component>
        </div>
      <!-- 图片显示 多图-->
        <div class="thumb-box" v-if="artObj.cover.type > 1">
          <lazy-component>
          <img
            class="thumb"
            v-for="(imgUrl, index) in artObj.cover.images"
            :key="index"
            v-lazy="imgUrl"
            alt=""
          />
          </lazy-component>
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ artObj.aut_name }}</span>
            <span>{{ artObj.comm_count }}评论</span>
            <span>{{ formData(artObj.pubdate) }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="crossShowFn" v-if="!$route.params.keyword" />
        </div>
      </template>
    </van-cell>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import * as relativeTime from 'dayjs/plugin/relativeTime' // import plugin
import 'dayjs/locale/zh-cn' // use locale

import { mapMutations } from 'vuex'

dayjs.extend(relativeTime) // use plugin
dayjs.locale('zh-cn')
export default {
  props: {
    artObj: Object
  },
  methods: {
    formData (oldDate) {
      var a = dayjs()
      var b = dayjs(oldDate)
      const c = a.to(b) // in 2 years
      return c
    },
    crossShowFn () {
      this.changeActionSheetModelMutations(true)
      this.setArtIdActionsMUtations(this.artObj.art_id)
      // console.log(this.artObj.art_id)
    },
    ...mapMutations([
      'changeActionSheetModelMutations',
      'setArtIdActionsMUtations'
    ])
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
